#  Copyright (c) 2014-present, Facebook, Inc.
#  All rights reserved.
#
#  This source code is licensed as defined on the LICENSE file found in the
#  root directory of this source tree.

load("//tools/build_defs/oss/osquery:cxx.bzl", "osquery_cxx_library", "osquery_cxx_test")
load("//tools/build_defs/oss/osquery:native.bzl", "osquery_target")
load("//tools/build_defs/oss/osquery:platforms.bzl", "FREEBSD", "LINUX", "MACOSX", "POSIX", "WINDOWS")
load("//tools/build_defs/oss/osquery:third_party.bzl", "osquery_tp_target")

osquery_cxx_library(
    name = "integration_tests_helper",
    srcs = [
        "helper.cpp",
    ],
    header_namespace = "osquery/tests/integration/tables",
    exported_headers = [
        "helper.h",
    ],
    deps = [
        osquery_target("osquery/sql:sql"),
        osquery_target("osquery/utils:utils"),
        osquery_target("plugins/database:ephemeral"),
        osquery_tp_target("boost"),
        osquery_tp_target("googletest", "gtest_headers"),
    ],
)

osquery_cxx_test(
    name = "tests",
    srcs = [
        "carbon_black_info.cpp",
        "carves.cpp",
        "chrome_extensions.cpp",
        "cpuid.cpp",
        "curl.cpp",
        "curl_certificate.cpp",
        "etc_hosts.cpp",
        "etc_protocols.cpp",
        "etc_services.cpp",
        "file.cpp",
        "firefox_addons.cpp",
        "groups.cpp",
        "hash.cpp",
        "interface_addresses.cpp",
        "interface_details.cpp",
        "listening_ports.cpp",
        "logged_in_users.cpp",
        "os_version.cpp",
        "osquery_events.cpp",
        "osquery_extensions.cpp",
        "osquery_flags.cpp",
        "osquery_info.cpp",
        "osquery_packs.cpp",
        "osquery_registry.cpp",
        "osquery_schedule.cpp",
        "platform_info.cpp",
        "process_memory_map.cpp",
        "process_open_sockets.cpp",
        "processes.cpp",
        "python_packages.cpp",
        "routes.cpp",
        "ssh_configs.cpp",
        "system_info.cpp",
        "time.cpp",
        "uptime.cpp",
        "user_groups.cpp",
        "users.cpp",
        "user_ssh_keys.cpp",

    ],
    platform_srcs = [
        (
            LINUX,
            [
                "arp_cache.cpp",
                "atom_packages.cpp",
                "deb_packages.cpp",
                "ec2_instance_metadata.cpp",
                "ec2_instance_tags.cpp",
                "elf_dynamic.cpp",
                "elf_info.cpp",
                "elf_sections.cpp",
                "elf_segments.cpp",
                "elf_symbols.cpp",
                "intel_me_info.cpp",
                "iptables.cpp",
                "kernel_info.cpp",
                "kernel_modules.cpp",
                "md_devices.cpp",
                "md_drives.cpp",
                "md_personalities.cpp",
                "memory_info.cpp",
                "memory_map.cpp",
                "msr.cpp",
                "npm_packages.cpp",
                "portage_keywords.cpp",
                "portage_packages.cpp",
                "portage_use.cpp",
                "process_file_events.cpp",
                "process_namespaces.cpp",
                "rpm_package_files.cpp",
                "rpm_packages.cpp",
                "selinux_events.cpp",
                "shadow.cpp",
                "shared_memory.cpp",
                "smart_drive_info.cpp",
                "socket_events.cpp",
                "syslog_events.cpp",
                "yara_events.cpp",
            ],
        ),
       (
            FREEBSD,
            [
                "fbsd_kmods.cpp",
                "pkg_packages.cpp",
            ],
        ),
        (
            POSIX,
            [
                "acpi_tables.cpp",
                "apt_sources.cpp",
                "augeas.cpp",
                "authorized_keys.cpp",
                "block_devices.cpp",
                "cpu_time.cpp",
                "crontab.cpp",
                "device_file.cpp",
                "device_hash.cpp",
                "device_partitions.cpp",
                "disk_encryption.cpp",
                "dns_resolvers.cpp",
                "docker_container_labels.cpp",
                "docker_container_mounts.cpp",
                "docker_container_networks.cpp",
                "docker_container_ports.cpp",
                "docker_container_processes.cpp",
                "docker_container_stats.cpp",
                "docker_containers.cpp",
                "docker_image_labels.cpp",
                "docker_images.cpp",
                "docker_info.cpp",
                "docker_network_labels.cpp",
                "docker_networks.cpp",
                "docker_version.cpp",
                "docker_volume_labels.cpp",
                "docker_volumes.cpp",
                "file_events.cpp",
                "hardware_events.cpp",
                "interface_ipv6.cpp",
                "known_hosts.cpp",
                "last.cpp",
                "lldp_neighbors.cpp",
                "load_average.cpp",
                "magic.cpp",
                "memory_array_mapped_addresses.cpp",
                "memory_arrays.cpp",
                "memory_device_mapped_addresses.cpp",
                "memory_devices.cpp",
                "memory_error_info.cpp",
                "mounts.cpp",
                "oem_strings.cpp",
                "opera_extensions.cpp",
                "pci_devices.cpp",
                "process_envs.cpp",
                "process_events.cpp",
                "process_open_files.cpp",
                "prometheus_metrics.cpp",
                "shell_history.cpp",
                "smbios_tables.cpp",
                "sudoers.cpp",
                "suid_bin.cpp",
                "system_controls.cpp",
                "ulimit_info.cpp",
                "usb_devices.cpp",
                "user_events.cpp",
                "yara.cpp",
                "yum_sources.cpp",
            ],
        ),
        (
            MACOSX,
            [
                "account_policy_data.cpp",
                "ad_config.cpp",
                "alf.cpp",
                "alf_exceptions.cpp",
                "alf_explicit_auths.cpp",
                "alf_services.cpp",
                "app_schemes.cpp",
                "apps.cpp",
                "arp_cache.cpp",
                "asl.cpp",
                "atom_packages.cpp",
                "authorization_mechanisms.cpp",
                "authorizations.cpp",
                "battery.cpp",
                "browser_plugins.cpp",
                "certificates.cpp",
                "crashes.cpp",
                "cups_destinations.cpp",
                "cups_jobs.cpp",
                "device_firmware.cpp",
                "disk_events.cpp",
                "event_taps.cpp",
                "extended_attributes.cpp",
                "fan_speed_sensors.cpp",
                "gatekeeper.cpp",
                "gatekeeper_approved_apps.cpp",
                "homebrew_packages.cpp",
                "ibridge.cpp",
                "iokit_devicetree.cpp",
                "iokit_registry.cpp",
                "kernel_extensions.cpp",
                "kernel_info.cpp",
                "kernel_panics.cpp",
                "keychain_acls.cpp",
                "keychain_items.cpp",
                "launchd.cpp",
                "launchd_overrides.cpp",
                "managed_policies.cpp",
                "mdfind.cpp",
                "nfs_shares.cpp",
                "nvram.cpp",
                "package_bom.cpp",
                "package_install_history.cpp",
                "package_receipts.cpp",
                "plist.cpp",
                "power_sensors.cpp",
                "preferences.cpp",
                "quicklook_cache.cpp",
                "running_apps.cpp",
                "safari_extensions.cpp",
                "sandboxes.cpp",
                "shared_folders.cpp",
                "sharing_preferences.cpp",
                "signature.cpp",
                "sip_config.cpp",
                "smart_drive_info.cpp",
                "smc_keys.cpp",
                "startup_items.cpp",
                "temperature_sensors.cpp",
                "time_machine_backups.cpp",
                "time_machine_destinations.cpp",
                "user_interaction_events.cpp",
                "virtual_memory_info.cpp",
                "wifi_networks.cpp",
                "wifi_status.cpp",
                "wifi_survey.cpp",
                "xprotect_entries.cpp",
                "xprotect_meta.cpp",
                "xprotect_reports.cpp",
                "yara_events.cpp",
            ],
        ),
        (
            WINDOWS,
            [
                "appcompat_shims.cpp",
                "arp_cache.cpp",
                "authenticode.cpp",
                "autoexec.cpp",
                "bitlocker_info.cpp",
                "certificates.cpp",
                "chocolatey_packages.cpp",
                "connectivity.cpp",
                "cpu_info.cpp",
                "default_environment.cpp",
                "disk_info.cpp",
                "drivers.cpp",
                "ie_extensions.cpp",
                "intel_me_info.cpp",
                "kernel_info.cpp",
                "kva_speculative_info.cpp",
                "logical_drives.cpp",
                "logon_sessions.cpp",
                "ntdomains.cpp",
                "ntfs_acl_permissions.cpp",
                "patches.cpp",
                "physical_disk_performance.cpp",
                "pipes.cpp",
                "powershell_events.cpp",
                "programs.cpp",
                "registry.cpp",
                "scheduled_tasks.cpp",
                "services.cpp",
                "shared_resources.cpp",
                "startup_items.cpp",
                "video_info.cpp",
                "winbaseobj.cpp",
                "windows_crashes.cpp",
                "windows_events.cpp",
                "wmi_bios_info.cpp",
                "wmi_cli_event_consumers.cpp",
                "wmi_event_filters.cpp",
                "wmi_filter_consumer_binding.cpp",
                "wmi_script_event_consumers.cpp",
                "windows_security_products.cpp",
            ],
        ),
    ],
    visibility = ["PUBLIC"],
    deps = [
        osquery_target("osquery/database:database"),
        osquery_target("osquery/events:events"),
        osquery_target("osquery/extensions:extensions"),
        osquery_target("osquery/extensions:impl_thrift"),
        osquery_target("osquery/remote/enroll:tls_enroll"),
        osquery_target("osquery/utils/conversions:conversions"),
        osquery_target("osquery/utils/info:info"),
        osquery_target("plugins/config:tls_config"),
        osquery_target("plugins/database:ephemeral"),
        osquery_target("specs:tables"),
        ":integration_tests_helper",
    ],
)
